<template>
  <div class='container'>
    <el-card v-loading="loading">
      <div class="top" width="100%">
        <span style="color:red;opacity:0.2;font-size:10px">说明：目前支持学科和关键字条件筛选</span>
        <el-button type="success" icon="el-icon-edit" size="small" @click="$router.push('/questions/new')">新增试题</el-button>
      </div>
      <el-form class="demo-form-inline" label-width="100px" ref="form" :model="form">
        <el-row>
          <el-col :span="6">
              <el-form-item label="学科" prop="subjectID">
                <el-select  placeholder="请选择" @focus="chooseSubject" v-model="form.subjectID">
                  <!-- 遍历列表得到 -->
                  <el-option
                  v-for="item in subjectsList"
                  :key="item.value"
                  :label='item.label'
                  :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
          </el-col>
          <el-col :span="6">
            <div class="grid-content bg-purple">
              <el-form-item label="二级目录" prop="catalogID">
                <el-select placeholder="请选择" v-model="form.catalogID" @focus="chooseCatalog">
                  <!-- 遍历列表得到 -->
                  <el-option
                  v-for="item in twoLevel"
                  :label="item.label"
                  :key="item.value"
                  :value="item.value">
                  </el-option>
                </el-select>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="6">
            <div class="grid-content bg-purple">
              <el-form-item label="标签" prop="tags">
                <el-select placeholder="请选择" v-model="form.tags" @focus="chooseTag">
                  <!-- 遍历列表得到 -->
                  <el-option
                  v-for="item in tagsList"
                  :label="item.label"
                  :key="item.value"
                  :value="item.label">
                  </el-option>
                </el-select>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="6">
            <div class="grid-content bg-purple">
              <el-form-item label="关键字" label-width="100px" prop="keyword">
                <el-input type="text" placeholder="根据题干搜索" v-model="form.keyword"></el-input>
              </el-form-item>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
            <div class="grid-content bg-purple">
              <el-form-item label="试题类型" prop="questionType">
                <el-select  placeholder="请选择" v-model="form.questionType">
                  <!-- 遍历列表得到 -->
                  <el-option
                  :label="item.label"
                  :value="item.value"
                  :key="item.value"
                  v-for="item in type">
                  </el-option>
                </el-select>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="6">
            <div class="grid-content bg-purple">
              <el-form-item label="难度" prop="difficulty">
                <el-select  placeholder="请选择" v-model="form.difficulty">
                  <!-- 遍历列表得到 -->
                  <el-option
                  :label="item.label"
                  :value="item.value"
                  :key="item.value"
                  v-for="item in diff">
                  </el-option>
                </el-select>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="6">
            <div class="grid-content bg-purple">
              <el-form-item label="方向" prop="direction">
                <el-select placeholder="请选择" v-model="form.direction">
                  <!-- 遍历列表得到 -->
                  <el-option
                  :label="item"
                  :value="index"
                  :key="index"
                  v-for="(item,index) in direction">
                  </el-option>
                </el-select>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="6">
            <div class="grid-content bg-purple">
              <el-form-item label="录入人" label-width="100px" prop="creatorID">
                <el-select placeholder="请选择" v-model="form.creatorID" @focus="chooseUser">
                  <!-- 遍历列表得到 -->
                  <el-option
                  v-for="item in entryList"
                  :label="item.username"
                  :key="item.id"
                  :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="6">
              <el-form-item label="题目备注" prop="remarks">
                <el-input type="text" v-model="form.remarks"></el-input>
              </el-form-item>
          </el-col>
          <el-col :span="6">
            <div class="grid-content bg-purple">
              <el-form-item label="企业简称" prop="shortName">
                <el-input type="text" v-model="form.shortName"></el-input>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="6">
              <el-row :gutter="5">
                <el-form-item label="城市">
                  <el-col :span="12">
                    <el-form-item prop="province">
                      <el-select v-model="form.province" @change="handleProvince">
                        <el-option v-for="(item,index) in provinces" :key="index" :value="item" :label="item"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col class="line" :span="2"></el-col>
                  <el-col :span="12">
                    <el-form-item prop="city">
                      <el-select v-model="form.city">
                        <el-option v-for="(item,index) in citys" :key="index" :value="item" :label="item"></el-option>
                      </el-select>
                    </el-form-item>
                  </el-col>
                </el-form-item>
              </el-row>
          </el-col>
          <el-col :span="6">
            <div class="grid-content bg-purple" id="last">
              <el-button size="small" @click="clear">清除</el-button>
              <el-button size="small" type="primary" @click="search">搜索</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>

      <!-- 列表部分 -->
      <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
        <el-tab-pane label="全部" name="first"></el-tab-pane>
        <el-tab-pane label="待审核" name="second"></el-tab-pane>
        <el-tab-pane label="已审核" name="third"></el-tab-pane>
        <el-tab-pane label="已拒绝" name="fourth"></el-tab-pane>
      </el-tabs>

       <el-alert
        :title="`数据一共`+totals+`条`"
        type="info"
        show-icon
        :closable="false">
      </el-alert>

       <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="number" label="试题编号" width="120">
        </el-table-column>
        <el-table-column prop="subject" label="学科" width="140">
        </el-table-column>
        <el-table-column prop="catalog" label="目录" width="180">
        </el-table-column>
        <el-table-column prop="questionType" label="题型" width="180" :formatter="formatQuestionType">
        </el-table-column>
        <el-table-column prop="question" label="题干" width="180">
          <template v-slot="scope">
                <p v-html='scope.row.question'></p>
          </template>
        </el-table-column>
        <el-table-column prop="addDate" label="录入时间" width="180">
          <template #default="{ row }">
            {{ row.addDate | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column prop="difficulty" label="难度" width="180" :formatter="formatDifficulty">
        </el-table-column>
        <el-table-column prop="creator" label="录入人" width="180">
        </el-table-column>
        <el-table-column prop="chkState" label="审核状态" width="180" :formatter="formatChkState">
        </el-table-column>
        <el-table-column prop="chkRemarks" label="审核意见" width="180">
        </el-table-column>
        <el-table-column prop="chkUser" label="审核人" width="180">
        </el-table-column>
        <el-table-column prop="publishState" label="发布状态" width="180">
          <template #default="{row}">
            <p>{{row.chkState | fnName(row.publishState)}}</p>
          </template>
        </el-table-column>
        <el-table-column prop="date" label="操作" width="200" fixed="right">
           <template #default="{row}">
            <el-button @click="clickFn(row)" type="text" size="small">预览</el-button>
            <el-button type="text" size="small" :disabled="row.chkState === 1 || row.chkState === 2" @click="check(row)">审核</el-button>
            <el-button type="text" size="small" :disabled="row.publishState === 1"  @click="$router.push(`/questions/new/?id=${row.id}`)">修改</el-button>
            <el-button type="text" size="small" v-if="row.publishState === 0" @click="go(row)">上架</el-button>
            <el-button type="text" size="small" v-else @click="back(row)">下架</el-button>
            <el-button type="text" size="small" @click="handleDel(row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[5, 10, 20, 50]"
        :page-size="5"
        :current-page.sync="currentPage"
        :hide-on-single-page="this.tableData.length <= 1"
        background
        layout="->,prev, pager, next, sizes,jumper"
        :total="totals"
        style="margin-top:20px"
        >
      </el-pagination>

      <!-- 审核弹窗 -->
      <el-dialog
        title="题目审核"
        :visible.sync="dialogVisible"
        width="400px"
        :before-close="handleClose">
        <span>
          <el-radio v-model="radio" label="1">通过</el-radio>
          <el-radio v-model="radio" label="2">拒绝</el-radio>
          <br><br><br>
          <el-form ref="check" :rules="rules" :model="formCheck">
            <el-form-item label="意见" prop="text">
              <el-input
                style="margin-bottom:20px"
                type="textarea"
                :rows="2"
                placeholder="请输入审核意见"
                v-model="formCheck.text">
              </el-input>
            </el-form-item>
          </el-form>
        </span>
        <!-- BUG 样式不对 -->
        <span slot="footer" class="dialog-footer">
          <el-button @click="handleClose">取 消</el-button>
          <el-button type="primary" @click="submit(radio)">确 定</el-button>
        </span>
      </el-dialog>

      <!-- 预览弹框 -->
      <el-dialog
        title="题目预览"
        :visible.sync="isShow"
        width="900px"
        @close="closeYL">
        <span>
          <el-descriptions :column='4'>
            <el-descriptions-item label="【题型】">{{view.questionType | aa}}题</el-descriptions-item>
            <el-descriptions-item label="【编号】">{{view.id}}</el-descriptions-item>
            <el-descriptions-item label="【难度】">{{view.difficulty | bb}}</el-descriptions-item>
            <el-descriptions-item label="【标签】">{{view.tags}}</el-descriptions-item>
            <el-descriptions-item label="【学科】">{{view.subjectName}}</el-descriptions-item>
            <el-descriptions-item label="【目录】">{{view.directoryName}}</el-descriptions-item>
            <el-descriptions-item label="【方向】">{{view.direction}}</el-descriptions-item>
          </el-descriptions>
          <hr>
          <el-descriptions direction="vertical">
            <el-descriptions-item label="【题干】"><div v-html="view.question" style="color:blue;margin-top:-20px"></div></el-descriptions-item>
          </el-descriptions>
            <div v-if="+view.questionType <= 2">
              <div style="margin-top:-15px" v-if="+view.questionType === 1">
              {{view.questionType | aa}}题 选项: （以下选中的选项为正确答案）<br><br>
              <el-radio
              v-model="radio"
              v-for="(item,index) in view.options"
              :key="item.id"
              :label="item.isRight"
              :value="item.id"
              style="display:block;margin-top:10px;"
              >
              {{view.options[index].title}}</el-radio>
            </div>
            <div v-else>
              {{view.questionType | aa}}题 选项: （以下选中的选项为正确答案）<br><br>
              <el-checkbox-group v-model="checkList">
                <el-checkbox
                :label="item.isRight"
                v-for="(item,index) in view.options"
                :key="item.id"
                :value="item.id"
                style="display:block"
                >
                {{view.options[index].title}}
                </el-checkbox>
              </el-checkbox-group>
            </div>
            </div>
            <!-- <div v-else>{{view.questionType | aa}}</div> -->
          <hr>
          <div>
            <el-descriptions>
            <el-descriptions-item label="【参考答案】">
              <el-button type="danger" size="mini" @click="answer">视频答案预览</el-button>
            </el-descriptions-item>
          </el-descriptions>
          <div>
                <video
                v-show="video"
                :src="view.videoURL"
                controls
                width="400px"
                height="300px"
              ></video>
              </div>
          </div>
          <hr>
          <div id="center" style="margin-bottom: -15px;">
            <el-descriptions>
              <el-descriptions-item label="【答案解析】"><div v-html="view.answer" style="margin-top:-12px"></div></el-descriptions-item>
            </el-descriptions>
          </div>
          <hr>
          <el-descriptions>
            <el-descriptions-item label="【题目备注】">{{view.remarks}}</el-descriptions-item>
          </el-descriptions>
        </span>
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="closeYL">关 闭</el-button>
        </span>
      </el-dialog>
    </el-card>
  </div>
</template>

<script>
import { simple } from '@/api/hmmm/subjects.js'
import { provinces, citys } from '@/api/hmmm/citys.js'
// import { reqGetSubjectsDetail } from '@/api/choice.js'
import { simple as simple1 } from '@/api/hmmm/directorys.js'
import { simple as simple2 } from '@/api/hmmm/tags.js'
import { difficulty, questionType, direction, chkType } from '@/api/hmmm/constants.js'
import { reqGetUserList } from '@/api/choice.js'
import { choice, remove, choicePublish, choiceCheck, detail } from '@/api/hmmm/questions.js'
export default {
  name: 'QuestionsChoice',
  data () {
    return {
      activeName: 'first',
      // 对话框
      dialogVisible: false,
      // 预览框
      isShow: false,
      // 预览信息
      view: [],
      // 预览选择答案
      checkList: [],
      // 审核弹窗数据
      rows: {},
      // 审核选择
      radio: '1',
      // 视频显示
      video: false,
      // 审核文本
      textarea: '',
      // 审核表单数据
      formCheck: {
        text: ''
      },
      rules: {
        text: [
          { required: true, message: '请输入审核意见', trigger: ['blur', 'change'] }
        ]
      },
      form: {
        subjectID: '',
        catalogID: '',
        tags: '',
        keyword: '',
        questionType: '',
        difficulty: '',
        direction: '',
        creatorID: '',
        remarks: '',
        shortName: '',
        province: '', // 城市
        city: '',
        id: ''
      },
      // 城市列表
      provinces: [],
      // 区域列表
      citys: [],
      // 下拉学科列表
      subjectsList: [],
      // 二级目录列表
      twoLevel: [],
      // 标签目录
      tagsList: [],
      // 录入人
      entryList: [],
      // 当前页数
      page: 1,
      // 分页指向
      currentPage: 1,
      // 页大小
      pagesize: 5,
      // 题目数量
      totals: 0,
      // 表格列表
      tableData: [],
      // 页面名字
      tabName: '',
      loading: false // 加载圈
    }
  },
  created () {
    // 获取列表
    this.getList()
    this.provinces = provinces()
  },
  filters: {
    // 状态码
    fnName: function (status, publishState) {
      if (status === 0 || status === 2) {
        return '待发布'
      } else {
        if (publishState === 0) {
          return '已下架'
        } else {
          return '已发布'
        }
      }
    },
    // 题型
    aa (status) {
      if (!status) return
      if (status === '1') {
        return '单选'
      }
      if (status === '2') { return '多选' }
      if (status === '3') { return '简答' }
    },
    // 难度
    bb (status) {
      if (!status) return
      if (status === '1') {
        return '简单'
      }
      if (status === '2') { return '一般' }
      if (status === '3') { return '困难' }
    }
  },
  computed: {
    diff () {
      return difficulty
    },
    type () {
      return questionType
    },
    direction () {
      return direction
    }
  },
  methods: {
    // 进入页面请求列表渲染
    async getList () {
      this.loading = true
      const obj = {}
      for (const key in this.form) {
        if (this.form[key]) {
          obj[key] = this.form[key]
        }
      }
      const { data } = await choice({ ...obj, page: this.page, pagesize: this.pagesize })
      // console.log(data)
      this.totals = data.counts
      this.tableData = data.items
      this.loading = false
    },
    // 请求下拉学科列表
    async chooseSubject () {
      // console.log(1)
      const { data } = await simple()
      // console.log(data)
      this.subjectsList = data
    },
    // 选择二级目录
    async chooseCatalog () {
      console.log(this.form.subjectID)
      if (!this.form.subjectID) return
      const res = await simple1({ subjectID: this.form.subjectID })
      // console.log(res)
      this.twoLevel = res.data
    },
    // 选择标签
    async chooseTag () {
      console.log(this.form.catalog)
      if (!this.form.catalog) return
      const { data } = await simple2({ subjectID: this.form.subjectID })
      // console.log(data)
      this.tagsList = data
    },
    // 选择录入人
    async chooseUser () {
      const { data } = await reqGetUserList()
      // console.log(data)
      this.entryList = data
    },
    // 处理城市联动
    handleProvince (pname) {
      this.citys = citys(pname)
    },
    // 清除数据
    clear () {
      this.$refs.form.resetFields()
      this.activeName = 'first'
      this.getList()
    },
    // 查找题库列表
    async search () {
      this.activeName = 'first'
      const obj = {}
      for (const key in this.form) {
        if (this.form[key]) {
          obj[key] = this.form[key]
        }
      }
      console.log(obj)
      const { data } = await choice({ ...obj, page: this.page, pagesize: this.pagesize })
      console.log(data)
      this.tableData = data.items
      this.totals = data.counts
    },
    // 切换页面
    async handleClick (tab, event) {
      const obj = {}
      for (const key in this.form) {
        if (this.form[key]) {
          obj[key] = this.form[key]
        }
      }
      // console.log(obj)
      const res = Object.keys(obj)
      // console.log(res)
      if (!res.length) {
        console.log(tab.name)
        this.tabName = tab.name
        if (tab.name === 'first') {
          this.currentPage = 1
          const { data } = await choice({ page: this.page, pagesize: this.pagesize })
          console.log(data)
          this.totals = data.counts
          this.tableData = data.items
        }
        if (tab.name === 'second') {
          this.page = 1
          this.currentPage = 1
          const { data } = await choice({ page: this.page, pagesize: this.pagesize, chkState: 0 })
          console.log(data)
          this.totals = data.counts
          this.tableData = data.items
        }
        if (tab.name === 'third') {
          this.currentPage = 1
          this.page = 1
          const { data } = await choice({ page: this.page, pagesize: this.pagesize, chkState: 1 })
          console.log(data)
          this.totals = data.counts
          this.tableData = data.items
        }
        if (tab.name === 'fourth') {
          this.currentPage = 1
          this.page = 1
          const { data } = await choice({ page: this.page, pagesize: this.pagesize, chkState: 2 })
          this.totals = data.counts
          this.tableData = data.items
        }
      } else {
        console.log(tab.name)
        this.tabName = tab.name
        if (tab.name === 'first') {
          this.currentPage = 1
          const { data } = await choice({ ...obj, page: this.page, pagesize: this.pagesize })
          console.log(data)
          this.totals = data.counts
          this.tableData = data.items
        }
        if (tab.name === 'second') {
          this.currentPage = 1
          this.page = 1
          const { data } = await choice({ ...obj, page: this.page, pagesize: this.pagesize, chkState: 0 })
          console.log(data)
          this.totals = data.counts
          this.tableData = data.items
        }
        if (tab.name === 'third') {
          this.currentPage = 1
          this.page = 1
          const { data } = await choice({ ...obj, page: this.page, pagesize: this.pagesize, chkState: 1 })
          console.log(data)
          this.totals = data.counts
          this.tableData = data.items
        }
        if (tab.name === 'fourth') {
          this.currentPage = 1
          this.page = 1
          const { data } = await choice({ ...obj, page: this.page, pagesize: this.pagesize, chkState: 2 })
          this.totals = data.counts
          this.tableData = data.items
        }
      }
    },
    // 查看预览 row
    async clickFn (row) {
      // console.log(row)
      this.isShow = true
      const { data } = await detail({ id: row.id })
      console.log(data, 66)
      this.view = data
      const res = data.options.find(item => item.isRight === 1)
      console.log(res)
      this.radio = res.isRight
      this.checkList.push(res.isRight)
    },
    // 预览关闭
    closeYL () {
      this.video = false
      this.isShow = false
    },
    // 处理题型 难度 状态格式
    formatQuestionType (row, column, cellValue, index) {
      const res = questionType.find(item => item.value === +cellValue)
      // console.log(res)
      return res ? res.label : '未知'
    },
    formatDifficulty (row, column, cellValue, index) {
      // console.log(row, column, cellValue, index)
      const res = difficulty.find(item => item.value === +cellValue)
      // console.log(res)
      return res ? res.label : '未知'
    },
    formatChkState (row, column, cellValue, index) {
      // console.log(row, column, cellValue, index)
      const res = chkType.find(item => item.value === +cellValue)
      // console.log(res)
      return res ? res.label : '未知'
    },
    // 处理分页
    async handleSizeChange (val) {
      // console.log(`每页 ${val} 条`)
      const obj = {}
      for (const key in this.form) {
        if (this.form[key]) {
          obj[key] = this.form[key]
        }
      }
      const res = Object.keys(obj)
      this.page = 1
      this.pagesize = val
      if (!res.length) { // 不携带表单参数
        console.log(this.tabName)
        if (this.tabName === 'first' || this.tabName === '') {
          const { data } = await choice({ page: this.page, pagesize: this.pagesize })
          console.log(data)
          this.totals = data.counts
          this.tableData = data.items
        }
        if (this.tabName === 'second') {
          this.page = 1
          const { data } = await choice({ page: this.page, pagesize: this.pagesize, chkState: 0 })
          console.log(data)
          this.totals = data.counts
          this.tableData = data.items
        }
        if (this.tabName === 'third') {
          this.page = 1
          const { data } = await choice({ page: this.page, pagesize: this.pagesize, chkState: 1 })
          console.log(data)
          this.totals = data.counts
          this.tableData = data.items
        }
        if (this.tabName === 'fourth') {
          this.page = 1
          const { data } = await choice({ page: this.page, pagesize: this.pagesize, chkState: 2 })
          this.totals = data.counts
          this.tableData = data.items
        }
      } else { // 携带表单参数
        if (this.tabName === 'first' || this.tabName === '') {
          const { data } = await choice({ ...obj, page: this.page, pagesize: this.pagesize })
          console.log(data)
          this.totals = data.counts
          this.tableData = data.items
        }
        if (this.tabName === 'second') {
          const { data } = await choice({ ...obj, page: this.page, pagesize: this.pagesize, chkState: 0 })
          console.log(data)
          this.totals = data.counts
          this.tableData = data.items
        }
        if (this.tabName === 'third') {
          const { data } = await choice({ ...obj, page: this.page, pagesize: this.pagesize, chkState: 1 })
          console.log(data)
          this.totals = data.counts
          this.tableData = data.items
        }
        if (this.tabName === 'fourth') {
          const { data } = await choice({ ...obj, page: this.page, pagesize: this.pagesize, chkState: 2 })
          this.totals = data.counts
          this.tableData = data.items
        }
      }
    },
    async handleCurrentChange (val) {
      console.log(`当前页: ${val}`)
      const obj = {}
      for (const key in this.form) {
        if (this.form[key]) {
          obj[key] = this.form[key]
        }
      }
      const res = Object.keys(obj)
      this.page = val
      if (!res.length) { // 不携带表单参数
        console.log(this.tabName)
        if (this.tabName === 'first' || this.tabName === '') {
          const { data } = await choice({ page: this.page, pagesize: this.pagesize })
          console.log(data)
          this.totals = data.counts
          this.tableData = data.items
        }
        if (this.tabName === 'second') {
          const { data } = await choice({ page: this.page, pagesize: this.pagesize, chkState: 0 })
          console.log(data)
          this.totals = data.counts
          this.tableData = data.items
        }
        if (this.tabName === 'third') {
          const { data } = await choice({ page: this.page, pagesize: this.pagesize, chkState: 1 })
          console.log(data)
          this.totals = data.counts
          this.tableData = data.items
        }
        if (this.tabName === 'fourth') {
          const { data } = await choice({ page: this.page, pagesize: this.pagesize, chkState: 2 })
          this.totals = data.counts
          this.tableData = data.items
        }
      } else { // 携带表单参数
        if (this.tabName === 'first' || this.tabName === '') {
          const { data } = await choice({ ...obj, page: this.page, pagesize: this.pagesize })
          console.log(data)
          this.totals = data.counts
          this.tableData = data.items
        }
        if (this.tabName === 'second') {
          const { data } = await choice({ ...obj, page: this.page, pagesize: this.pagesize, chkState: 0 })
          console.log(data)
          this.totals = data.counts
          this.tableData = data.items
        }
        if (this.tabName === 'third') {
          const { data } = await choice({ ...obj, page: this.page, pagesize: this.pagesize, chkState: 1 })
          console.log(data)
          this.totals = data.counts
          this.tableData = data.items
        }
        if (this.tabName === 'fourth') {
          const { data } = await choice({ ...obj, page: this.page, pagesize: this.pagesize, chkState: 2 })
          this.totals = data.counts
          this.tableData = data.items
        }
      }
    },
    // 删除表格
    handleDel (id) {
      this.$confirm('是否确定删除?', '提示').then(async () => {
        const res = await remove(({ id }))
        console.log(res)
        this.$message.success('删除成功!!')
        if (this.tableData.length === 1 && this.page > 1) {
          this.page--
        }
        this.getList()
      }).catch(() => {
        console.log('取消')
      })
    },
    change (id) {
      console.log(id)
    },
    // 上下 架
    go (row) {
      console.log(this.tabName)
      console.log(row.chkState)
      // BUG 进入页面不也换页面 再点击上下架 更新列表会失败
      this.$confirm('您确认上架这道题目吗?', '提示', { type: 'warning' }).then(async () => {
        const res = await choicePublish(
          {
            id: row.id,
            publishState: 1
          })
        console.log(res)
        this.$message.success('上架成功')
        if (this.tabName !== 'first' && this.tabName !== '') {
          const { data } = await choice({ page: this.page, pagesize: this.pagesize, chkState: row.chkState })
          console.log(data)
          this.totals = data.counts
          this.tableData = data.items
        } else {
          this.getList()
        }
      }).catch(() => {
        console.log('取消')
      })
    },
    back (row) {
      this.$confirm('您确认下架这道题目吗?', '提示', { type: 'warning' }).then(async () => {
        const res = await choicePublish(
          {
            id: row.id,
            publishState: 0
          })
        console.log(res)
        this.$message.success('下架成功')
        if (this.tabName !== 'first' && this.tabName !== '') {
          const { data } = await choice({ page: this.page, pagesize: this.pagesize, chkState: row.chkState })
          console.log(data)
          this.totals = data.counts
          this.tableData = data.items
        } else {
          this.getList()
        }
      }).catch(() => {
        console.log('取消')
      })
    },
    // 审核意见
    check (row) {
      this.dialogVisible = true
      console.log(row)
      this.rows = row
    },
    // 审核框
    handleClose () {
      this.dialogVisible = false
      this.isShow = false
      this.$refs.check.resetFields()
      this.radio = '1'
    },
    // BUG审核框提交
    submit (radio) {
      console.log(this.rows.chkState)
      this.$refs.check.validate(async (flag) => {
        console.log(radio)
        console.log(this.formCheck.text)
        if (!flag) {
          return this.$message.warning('请输入审核意见！')
        }
        // 通过 审核码变为1
        this.rows.chkState = 1
        console.log(this.rows.id)
        const data1 = {
          id: this.rows.id,
          chkRemarks: this.formCheck.text,
          chkState: +radio
        }
        const { data } = await choiceCheck(data1)
        console.log(data)
        if (this.tabName === 'first' || this.tabName === '') {
          const res = await choice({ page: this.page, pagesize: this.pagesize })
          this.totals = res.data.counts
          this.tableData = res.data.items
        } else {
          const res = await choice({ page: this.page, pagesize: this.pagesize, chkState: 0 })
          this.totals = res.data.counts
          this.tableData = res.data.items
        }
        // console.log(res)
        this.radio = '1'
        this.$refs.check.resetFields()
        this.dialogVisible = false
      })
    },
    // 视频答案
    answer () {
      console.log('qq')
      this.video = !this.video
    }
  }
}
</script>

<style scoped lang='scss'>
  .container{
    #center {
      text-align: center;
      padding-top: 10px;
    }
    padding: 10px;
    .top {
      display: flex;
      justify-content: space-between;
      margin-bottom: 10px;
    }
    .demo-form-inline {
      // margin-left: 40px
      font-size: 14px;
      .grid-content {
        padding-left: 0px;
      }
      ::v-deep #last {
        float: right;
      }
    }
  }
</style>
